// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.iso.areas.isoregion;

import java.util.ArrayList;
import java.util.concurrent.ConcurrentLinkedQueue;
import zombie.core.Color;
import zombie.core.Core;
import zombie.debug.DebugLog;

public class IsoRegionsLogger {
    private final ConcurrentLinkedQueue<IsoRegionsLogger.IsoRegionLog> pool = new ConcurrentLinkedQueue();
    private final ConcurrentLinkedQueue<IsoRegionsLogger.IsoRegionLog> loggerQueue = new ConcurrentLinkedQueue();
    private final boolean consolePrint;
    private final ArrayList<IsoRegionsLogger.IsoRegionLog> logs = new ArrayList();
    private final int maxLogs = 100;
    private boolean isDirtyUI = false;

    public IsoRegionsLogger(boolean doConsolePrint) {
        this.consolePrint = doConsolePrint;
    }

    public ArrayList<IsoRegionsLogger.IsoRegionLog> getLogs() {
        return this.logs;
    }

    public boolean isDirtyUI() {
        return this.isDirtyUI;
    }

    public void unsetDirtyUI() {
        this.isDirtyUI = false;
    }

    private IsoRegionsLogger.IsoRegionLog getLog() {
        IsoRegionsLogger.IsoRegionLog isoRegionLog = (IsoRegionsLogger.IsoRegionLog)this.pool.poll();
        if (isoRegionLog == null) {
            isoRegionLog = new IsoRegionsLogger.IsoRegionLog();
        }

        return isoRegionLog;
    }

    protected void log(String string) {
        this.log(string, null);
    }

    protected void log(String string, Color color) {
        if (Core.bDebug) {
            if (this.consolePrint) {
                DebugLog.IsoRegion.println(string);
            }

            IsoRegionsLogger.IsoRegionLog isoRegionLog = this.getLog();
            isoRegionLog.str = string;
            isoRegionLog.type = IsoRegionLogType.Normal;
            isoRegionLog.col = color;
            this.loggerQueue.offer(isoRegionLog);
        }
    }

    protected void warn(String string) {
        DebugLog.IsoRegion.warn(string);
        if (Core.bDebug) {
            IsoRegionsLogger.IsoRegionLog isoRegionLog = this.getLog();
            isoRegionLog.str = string;
            isoRegionLog.type = IsoRegionLogType.Warn;
            this.loggerQueue.offer(isoRegionLog);
        }
    }

    protected void update() {
        if (Core.bDebug) {
            for (IsoRegionsLogger.IsoRegionLog isoRegionLog0 = (IsoRegionsLogger.IsoRegionLog)this.loggerQueue.poll();
                isoRegionLog0 != null;
                isoRegionLog0 = (IsoRegionsLogger.IsoRegionLog)this.loggerQueue.poll()
            ) {
                if (this.logs.size() >= 100) {
                    IsoRegionsLogger.IsoRegionLog isoRegionLog1 = (IsoRegionsLogger.IsoRegionLog)this.logs.remove(0);
                    isoRegionLog1.col = null;
                    this.pool.offer(isoRegionLog1);
                }

                this.logs.add(isoRegionLog0);
                this.isDirtyUI = true;
            }
        }
    }

    public static class IsoRegionLog {
        private String str;
        private IsoRegionLogType type;
        private Color col;

        public String getStr() {
            return this.str;
        }

        public IsoRegionLogType getType() {
            return this.type;
        }

        public Color getColor() {
            if (this.col != null) {
                return this.col;
            } else {
                return this.type == IsoRegionLogType.Warn ? Color.red : Color.white;
            }
        }
    }
}
